<!DOCTYPE html>
<html>
<body>
<script src="/js-test-resources/js-test.js"></script>
<script>
description("The pattern created by OffscreenCanvas2D from cross-origin image must be tainted.");

function shouldBeTainted(pattern) {
    var canvas = document.createElement("canvas");
    canvas.width = 10;
    canvas.height = 10;
    var context = canvas.getContext("2d");
    // Setting tainted pattern as fillStyle on HTMLCanvas will taint the canvas.
    context.fillStyle = pattern;
    context.fillRect(0, 0, canvas.width, canvas.height);
    try {
        var imageData = context.getImageData(0, 0, 10, 10);
        testFailed("ImageBitmap is not tainted.");
    } catch (e) {
        testPassed("ImageBitmap is tainted. Threw error: " + e);
    }
}

var image = document.createElement('img');
image.src = 'http://localhost:8080/security/resources/abe.png';
image.addEventListener('load', function() {
    var offscreenCanvas = new OffscreenCanvas(10, 10);
    var offscreenContext = offscreenCanvas.getContext("2d");
    var pat = offscreenContext.createPattern(image, "no-repeat");
    shouldBeTainted(pat);
 });

</script>
</body>
</html>
